<template>
    <div class="user-assets-box">
        <div class="lists">
            <item
                    v-for="(item, index) of lists"
                    :to="{name: 'user-cash_details', query: {room_id: item.room_id}}"
                    border="10"
                    :key="index">
                <div class="item">
                    <div class="info">
                        <div class="room">
                            <span>&#xe600;</span>
                            房间号：{{item.room_id}}
                        </div>
                    </div>
                    <div class="gold">
                        <span style="color: #FF8D24">&#xe934;</span>
                        {{item.number}}
                    </div>
                </div>
            </item>
        </div>
        <next-page
                :loading="loading"
                :more="full"
                :data="lists.length===0"
                @more="loadMore"></next-page>
    </div>
</template>

<script>
    import apiUrl from '@/api/apiUrl'
    import {Toast} from 'mint-ui'
    import nextPage from '../../../components/nextPage'
    import Item from '../../../components/item'

    export default {
        name: "index",
        data () {
            return {
                lists: [],
                loading: false,
                full: false,
                page: 1,
                row: 20
            }
        },
        beforeRouteEnter(to, from, next) {
            next(vm => {
                vm.setData()
            })
        },
        components: {
            nextPage,
            Item
        },
        methods: {
            loadMore() {
                if (this.lists.length < this.row) {
                    this.loading = false
                } else {
                    this.loading = true
                    this.$set(this, 'page', this.page + 1)
                    this.setData(this.page, this.row, res => {
                        this.loading = false;
                        if (res.length === 0) {
                            this.$set(this, 'full', true)
                        }
                    })
                }
            },
            setData (page = 1, row = 20, fun = null) {
                let params = {
                    params: {
                        page: page,
                        row: row
                    }
                }
                this.$http.get(apiUrl.api.user_gold, params).then(res => {
                    if (res.data.code === 0) {
                        this.$set(this, 'lists', this.lists.concat(res.data.result))
                        if (fun !== null) {
                            fun(res.data.result)
                        }
                        if (res.data.result.length < 20) {
                            this.full = true
                        }
                    } else {
                        Toast(res.data.msg)
                    }
                }).catch(err => {
                    console.log(err)
                })
            }
        }
    }
</script>

<style scoped lang="less">
    @import "../../../assets/css/bases";
    .item {
        display: flex;
        justify-content: space-between;
        align-items: center;
        .time {
            color: @gray;
            line-height: 35px;
        }
        .frequency {
            color: @gray;
        }
    }
</style>